from random import randint
from domain.namegen import generate_name

ATT_PASS = 0
ATT_SCORE = 1
ATT_MARK = 2
ATT_SPEED = 3
ATT_TECHNIQUE = 4
ATTRIBUTES = [ATT_PASS, ATT_SCORE, ATT_MARK, ATT_SPEED, ATT_TECHNIQUE]


class Player(object):
    
    def __init__(self, name=None, nationality=None, atts=None):
        if name is None:
            n = generate_name(nationality)
        else:
            n = name
        self.name = n
        
        if atts is None:
            a = dict([(att, randint(51, 100)) for att in ATTRIBUTES]) 
        else:
            if any([att not in atts for att in ATTRIBUTES]):
                raise ValueError('Player has to be initialized with all '
                                 'attributes')
            a = dict(atts)
        self.attributes = a

    def __str__(self):
        return self.name
